package com.booby.algorithm.shell;

import com.booby.algorithm.utils.Utils;

/**
 * 功能描述: 希尔排序，从大到小
 *
 * @author: lizt
 * @date: 2020/8/23 15:02
 **/

public class MaxToMin {
    public static final Integer[] arr = {9,6,11,3,5,12,8,7,10,15,14,4,1,13,2};

    public static void sorted(Integer[] arr){
        int len = arr.length;
        int h = (len-1)/3;
        for (int gap = h; gap > 0; gap = (gap-1)/3) {
            for (int i = 0; i < len-gap; i+=gap) {
                int currentIndex = i + gap;
                for (int j = 0; j < currentIndex; j+=gap) {
                    if (arr[currentIndex] > arr[j]){
                        Utils.swap(arr, currentIndex, j);
                    }
                }
            }

        }
    }

    public static void main(String[] args) {
        sorted(arr);
        Utils.print(arr);
    }
}
